home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / xceedzip / MAIN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-04-26  |  34.5 KB  |  786 lines

  1. unit Main;
  2. {==================================================================}
  3. { Description: Getting Started Sample Application                  }
  4. { Copyright:   ⌐ Copyright 1995-1999 Xceed Software Inc.           }
  5. {                All Rights Reserved.                              }
  6. {==================================================================}
  7.  
  8. interface
  9.  
  10. uses
  11.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  12.   OleCtrls, XceedZipLib_TLB, ComCtrls, StdCtrls, checklst;
  13.  
  14. const
  15.   { Property hints }
  16.   cBasePathHint = 'BasePath property:' + #13#10 +
  17.     '    This path determines where entries in the FilesToProcess and FilesToExclude' + #13#10 +
  18.     '    properties are relative to. The base path never appears in the zip file, even if' + #13#10 +
  19.     '    PreservePaths = True. Only the portion of the path and filename specified in' + #13#10 +
  20.     '    the FilesToProcess property is actually stored in the zip file. Therefore,' + #13#10 +
  21.     '    BasePath helps you control what portions of paths are stored in the zip file.' + #13#10 +
  22.     '    (The BasePath property is irrelevant when you are using absolute paths)';
  23.  
  24.   cFilesToProcessHint = 'FilesToProcess property:' + #13#10 +
  25.     '    Multiline string that contains all the filenames and/or file masks to be' + #13#10 +
  26.     '    processed (zipped, unzipped, etc). If you entered a path in the' + #13#10 +
  27.     '    BasePath property, all entries with relative paths will be relative to' + #13#10 +
  28.     '    the specified base path. The pipe character can be used instead of' + #13#10 +
  29.     '    the linefeed to separate entries for the FilesToProcess property.';
  30.  
  31.   cFilesToExcludeHint = 'FilesToExclude property:' + #13#10 +
  32.     '    Multiline string that contains all filenames and/or file masks to exclude' + #13#10 +
  33.     '    from the files to be processed by the FilesToProcess property. These' + #13#10 +
  34.     '    entries are also relative to the path specified in the BasePath property' + #13#10 +
  35.     '    if its not empty.';
  36.  
  37.   cProcessSubfoldersHint = 'ProcessSubfolders property:' + #13#10 +
  38.     '    If set to True, the contents of all encoutered subfolders will be processed.';
  39.  
  40.   cZipFilenameHint = 'ZipFilename property:' + #13#10 +
  41.     '    The filename of the zip file to work with. When unzipping, this file must' + #13#10 +
  42.     '    exist. When zipping, if the file exists, it''s updated. Otherwise, it is' + #13#10 +
  43.     '    created. You must enter an absolute path for this property. The' + #13#10 +
  44.     '    BasePath property does not interfere with the ZipFilename property.';
  45.  
  46.   cPreservePathsHint = 'PreservePaths property:' + #13#10 +
  47.     '    If set to True, the zip file will store both the path and the filename of' + #13#10 +
  48.     '    each file that is being zipped. As usual, the portion of a file''s path' + #13#10 +
  49.     '    that is specified in the BasePath property will not be stored in the' + #13#10 +
  50.     '    zip file. When PreservePaths is set to False, only filenames (no' + #13#10 +
  51.     '    paths) are stored.';
  52.  
  53.   cUseTempFileHint = 'UseTempFile property:' + #13#10 +
  54.     '    If set to true, all zipping operations will be performed on a temp file' + #13#10 +
  55.     '    located in the folder specified in the TempFolder property.' + #13#10 +
  56.     '    Otherwise, the operation is performed directly on the zip file' + #13#10 +
  57.     '    without using a temp file. You cannot remove files from an existing' + #13#10 +
  58.     '    zip file, or update files already in an existing zip files without setting' + #13#10 +
  59.     '    this property to True.';
  60.  
  61.   cTempFolderHint = 'TempFolder property:' + #13#10 +
  62.     '    Location of the temp file when the UseTempFile property is set to True.' + #13#10 +
  63.     '    When you leave this property empty, the Windows default temp' + #13#10 +
  64.     '    directory is used.';
  65.  
  66.   cRequiredFileAttributesHint = 'RequiredFileAttributes property:' + #13#10 +
  67.     '    Bit-field value that specifies all attributes that a file must have in' + #13#10 +
  68.     '    order to be included in the process.';
  69.  
  70.   cExcludedFileAttributesHint = 'ExcludedFileAttributes property:' + #13#10 +
  71.     '    Bit-field value that specifies all attributes that a file must NOT have' + #13#10 +
  72.     '    in order to be included in the process.';
  73.  
  74.   cMinDateToProcessHint = 'MinDateToProcess property:' + #13#10 +
  75.     '    Minimum value of a file''s ''Last modifed date'' required in order to be' + #13#10 +
  76.     '    included in the process.';
  77.  
  78.   cMaxDateToProcessHint = 'MaxDateToProcess property:' + #13#10 +
  79.     '    Maximum value of a file''s ''Last modifed date'' required in order to be' + #13#10 +
  80.     '    included in the process.';
  81.  
  82.   cMinSizeToProcessHint = 'MinSizeToProcess property:' + #13#10 +
  83.     '    Minimum file size that a file must have in order to be included in the process.';
  84.  
  85.   cMaxSizeToProcessHint = 'MaxSizeToProcess property:' + #13#10 +
  86.     '    Maximum file size that a file must have in order to be included in the process.';
  87.  
  88.   cUnzipToFolderHint = 'UnzipToFolder property:' + #13#10 +
  89.     '    Destination folder for files being unzipped. In this sample, the PreservePaths' + #13#10 +
  90.     '    property is set to True, so if files are stored in the zip file with paths, those' + #13#10 +
  91.     '    stored paths will be recreated inside the destination folder specified by the' + #13#10 +
  92.     '    UnzipToFolder property.';
  93.  
  94.   cSkipIfExistingHint = 'SkipIfExisting property:' + #13#10 +
  95.     '    If the destination file (located in a zip file that is being updated, or' + #13#10 +
  96.     '    on disk when a zip file is being unzipped) already exists, and this' + #13#10 +
  97.     '    property is set to True, then the file won''t be overwritten. This has' + #13#10 +
  98.     '    the effect of only processing files that don''t exist in the destination' + #13#10 +
  99.     '    zip file or unzipping folder.';
  100.  
  101.   cSkipIfNotExistingHint = 'SkipIfNotExisting property:' + #13#10 +
  102.     '    Setting this property to True will cause only files that don''t already' + #13#10 +
  103.     '    exist in the destination unzipping location (when unzipping) or the' + #13#10 +
  104.     '    zip file (when zipping) to be skipped.';
  105.  
  106.   cSkipIfOlderDateHint = 'SkipIfOlderDate property:' + #13#10 +
  107.     '    When updating a file (in a zip while zipping, or on disk while unzipping),' + #13#10 +
  108.     '    the file is skipped if the existing file''s ''Last modified date'' is greater than' + #13#10 +
  109.     '    the file being zipped or unzipped.';
  110.  
  111.   cSkipIfOlderVersionHint = 'SkipIfOlderVersion property:' + #13#10 +
  112.     '    When updating a file (in a zip while zipping, or on disk while unzipping),' + #13#10 +
  113.     '    the file is skipped if the existing file''s version resource value is greater' + #13#10 +
  114.     '    than the file being zipped or unzipped.';
  115.  
  116.   cZipFilenameSfxHint = 'ZipFilename property with Sfx:' + #13#10 +
  117.     '    The filename of the zip file to work on. When creating or updating' + #13#10 +
  118.     '    self-extracting zip files, you should enter an executable filename' + #13#10 +
  119.     '    (use a .EXE extension).';
  120.  
  121.   cSfxBinaryModuleHint  = 'SfxBinaryModule property:' + #13#10 +
  122.     '    This binary file will be prepended to the zip file, with configuration' + #13#10 +
  123.     '    data if the binary is one of the Xceed Self-Extractor Module' + #13#10 +
  124.     '    binaries. If you leave this field empty, a regular (non-sfx) zip file' + #13#10 +
  125.     '    will be created.';
  126.  
  127.   cSfxStringsHint = 'SfxStrings property array:' + #13#10 +
  128.     '    This array contains all the strings displayed by the Xceed Self-Extractor' + #13#10 +
  129.     '    Module binaries. For example, the ''xssTitle'' index contains the title' + #13#10 +
  130.     '    displayed by all dialog boxes.';
  131.  
  132.   cSfxMessagesHint  = 'SfxMessages property array:' + #13#10 +
  133.     '    This array contains all messages displayed by the Xceed Self-Extractor Module' + #13#10 +
  134.     '    binaries. These messages often appear in their own dialog boxes. If a particular' + #13#10 +
  135.     '    message is left empty, the dialog box won''t be displayed. As an example,' + #13#10 +
  136.     '    leaving this field empty will avoid displaying an introduction message dialog.';
  137.  
  138.   { Method hints }
  139.   cPreviewFilesHint = 'PreviewFiles method:' + #13#10 +
  140.     '    Lets you scan the disk for files that would be zipped with the current property' + #13#10 +
  141.     '    settings. A PreviewingFile event is triggered for each file that matches an' + #13#10 +
  142.     '    entry in the FilesToProcess property. Set this method''s parameter to True to' + #13#10 +
  143.     '    have the library calculate the compressed size of the previewed files.';
  144.  
  145.   cListZipContentsHint = 'ListZipContents method:' + #13#10 +
  146.     '    Lets you view the zip file''s contents. Due to the fact that the FilesToProcess' + #13#10 +
  147.     '    property and the other filtering properties affect the ListZipContents method,' + #13#10 +
  148.     '    you can use it to preview which files would be unzipped by the Unzip method' + #13#10 +
  149.     '    if it were called with the current property settings. A ListingFile event is' + #13#10 +
  150.     '    triggered for each file in the zip file that is listed.';
  151.  
  152.   cZipHint = 'Zip method:' + #13#10 +
  153.     '    Lets you zip files. Only files that match all the entries in the FilesToProcess' + #13#10 +
  154.     '    and filtering properties will be processed. For each file that matches the' + #13#10 +
  155.     '    FilesToProcess property, the ZipPreprocessingFile event is triggered. That' + #13#10 +
  156.     '    event provides you with the chance to change the inclusion state of a file,' + #13#10 +
  157.     '    or to change its information before it is stored in the zip file.';
  158.  
  159.   cUnzipHint = 'Unzip method:' + #13#10 +
  160.     '    Lets you unzip files. Only files that match all the entries in the FilesToProcess' + #13#10 +
  161.     '    and filtering properties will be processed. For each file that matches the' + #13#10 +
  162.     '    FilesToProcess property, the UnzipPreprocessingFile event is triggered. That' + #13#10 +
  163.     '    event provides you with the chance to change the inclusion state of a file, or' + #13#10 +
  164.     '    to change its information before it is written to the destination unzipping folder.';
  165.  
  166.   cZipSfxHint = 'Zip method with Sfx:' + #13#10 +
  167.     '    It''s just like creating a regular (non-sfx) zip file, but if you enter a value' + #13#10 +
  168.     '    for the SfxBinaryModule property, the binary (or any file for that matter)' + #13#10 +
  169.     '    is prepended to the zip file. The zip file is now self-extracting because' + #13#10 +
  170.     '    the binary knows how to unzip the rest of the data after itself.' + #13#10 +
  171.     '    Furthermore, if the library recognises an Xceed binary, it will add' + #13#10 +
  172.     '    config data to the binary so that the self-extracting zip file can display' + #13#10 +
  173.     '    intro messages and have custom behavior.';
  174.     
  175. type
  176.   TfrmMain = class(TForm)
  177.     Label1: TLabel;
  178.     shtPreview: TTabSheet;
  179.     shtZip: TTabSheet;
  180.     shtList: TTabSheet;
  181.     shtUnzip: TTabSheet;
  182.     shtSFX: TTabSheet;
  183.     tabExamples: TPageControl;
  184.     Label3: TLabel;
  185.     edtPFilesToProcess: TMemo;
  186.     Label4: TLabel;
  187.     edtPFilesToExclude: TMemo;
  188.     Label5: TLabel;
  189.     lstPRequiredFileAttributes: TCheckListBox;
  190.     lstPExcludedFileAttributes: TCheckListBox;
  191.     Label6: TLabel;
  192.     chkPProcessSubfolders: TCheckBox;
  193.     btPreviewFiles: TButton;
  194.     StatusBar1: TStatusBar;
  195.     Label7: TLabel;
  196.     edtResults: TMemo;
  197.     Label8: TLabel;
  198.     Label9: TLabel;
  199.     edtZZipFilename: TEdit;
  200.     Label10: TLabel;
  201.     edtZBasePath: TEdit;
  202.     Label11: TLabel;
  203.     edtZFilesToProcess: TMemo;
  204.     Label12: TLabel;
  205.     edtZFilesToExclude: TMemo;
  206.     chkZPreservePaths: TCheckBox;
  207.     chkZProcessSubfolders: TCheckBox;
  208.     chkZUseTempFile: TCheckBox;
  209.     Label13: TLabel;
  210.     edtZTempFolder: TEdit;
  211.     btZip: TButton;
  212.     Label14: TLabel;
  213.     Label15: TLabel;
  214.     Label16: TLabel;
  215.     Label17: TLabel;
  216.     edtLZipFilename: TEdit;
  217.     Label18: TLabel;
  218.     Label19: TLabel;
  219.     Label20: TLabel;
  220.     edtLMinSizeToProcess: TEdit;
  221.     Label21: TLabel;
  222.     edtLMaxSizeToProcess: TEdit;
  223.     btList: TButton;
  224.     dtLMinDateToProcess: TDateTimePicker;
  225.     dtLMaxDateToProcess: TDateTimePicker;
  226.     Label23: TLabel;
  227.     edtUZipFilename: TEdit;
  228.     Label24: TLabel;
  229.     edtUUnzipToFolder: TEdit;
  230.     Label25: TLabel;
  231.     edtUFilesToProcess: TMemo;
  232.     Label26: TLabel;
  233.     edtUFilesToExclude: TMemo;
  234.     chkUSkipIfExisting: TCheckBox;
  235.     chkUSkipIfNotExisting: TCheckBox;
  236.     chkUSkipIfOlderDate: TCheckBox;
  237.     chkUSkipIfOlderVersion: TCheckBox;
  238.     btUnzip: TButton;
  239.     Label29: TLabel;
  240.     edtSZipFilename: TEdit;
  241.     Label30: TLabel;
  242.     edtSFilesToProcess: TMemo;
  243.     Label31: TLabel;
  244.     edtSSfxBinaryModule: TEdit;
  245.     Label32: TLabel;
  246.     edtSTitle: TEdit;
  247.     btZipSfx: TButton;
  248.     Label33: TLabel;
  249.     edtSIntro: TMemo;
  250.     barFile: TProgressBar;
  251.     barGlobal: TProgressBar;
  252.     xZip: TXceedZip;
  253.     Memo1: TMemo;
  254.     Memo2: TMemo;
  255.     Memo3: TMemo;
  256.     procedure FormCreate(Sender: TObject);
  257.     procedure btPreviewFilesClick(Sender: TObject);
  258.     procedure btZipClick(Sender: TObject);
  259.     procedure btListClick(Sender: TObject);
  260.     procedure btUnzipClick(Sender: TObject);
  261.     procedure btZipSfxClick(Sender: TObject);
  262.     procedure xZipInsertDisk(Sender: TObject; nDiskNumber: Integer;
  263.       var bDiskInserted: WordBool);
  264.     procedure xZipWarning(Sender: TObject; const sFilename: WideString;
  265.       xWarning: TOleEnum);
  266.     procedure xZipListingFile(Sender: TObject; const sFilename,
  267.       sComment: WideString; lSize, lCompressedSize: Integer;
  268.       nCompressionRatio: Smallint; xAttributes: TOleEnum; lCRC: Integer;
  269.       dtLastModified, dtLastAccessed, dtCreated: TDateTime;
  270.       xMethod: TOleEnum; bEncrypted: WordBool; lDiskNumber: Integer;
  271.       bExcluded: WordBool; xReason: TOleEnum);
  272.     procedure xZipPreviewingFile(Sender: TObject; const sFilename,
  273.       sSourceFilename: WideString; lSize: Integer; xAttributes: TOleEnum;
  274.       dtLastModified, dtLastAccessed, dtCreated: TDateTime;
  275.       bExcluded: WordBool; xReason: TOleEnum);
  276.     procedure xZipSkippingFile(Sender: TObject; const sFilename, sComment,
  277.       sFilenameOnDisk: WideString; lSize, lCompressedSize: Integer;
  278.       xAttributes: TOleEnum; lCRC: Integer; dtLastModified, dtLastAccessed,
  279.       dtCreated: TDateTime; xMethod: TOleEnum; bEncrypted: WordBool;
  280.       xReason: TOleEnum);
  281.     procedure xZipFileStatus(Sender: TObject; const sFilename: WideString;
  282.       lSize, lCompressedSize, lBytesProcessed: Integer; nBytesPercent,
  283.       nCompressionRatio: Smallint; bFileCompleted: WordBool);
  284.     procedure xZipGlobalStatus(Sender: TObject; lFilesTotal,
  285.       lFilesProcessed, lFilesSkipped: Integer; nFilesPercent: Smallint;
  286.       lBytesTotal, lBytesProcessed, lBytesSkipped: Integer;
  287.       nBytesPercent: Smallint; lBytesOutput: Integer;
  288.       nCompressionRatio: Smallint);
  289.     procedure xZipProcessCompleted(Sender: TObject; lFilesTotal,
  290.       lFilesProcessed, lFilesSkipped, lBytesTotal, lBytesProcessed,
  291.       lBytesSkipped, lBytesOutput: Integer; nCompressionRatio: Smallint;
  292.       xResult: TOleEnum);
  293.     procedure xZipReplacingFile(Sender: TObject; const sFilename,
  294.       sComment: WideString; lSize: Integer; xAttributes: TOleEnum;
  295.       dtLastModified, dtLastAccessed, dtCreated: TDateTime;
  296.       const sOrigFilename: WideString; lOrigSize: Integer;
  297.       xOrigAttributes: TOleEnum; dtOrigLastModified, dtOrigLastAccessed,
  298.       dtOrigCreated: TDateTime; var bReplaceFile: WordBool);
  299.     procedure xZipZipContentsStatus(Sender: TObject; lFilesRead,
  300.       lFilesTotal: Integer; nFilesPercent: Smallint);
  301.   private
  302.     { Private declarations }
  303.     procedure UpdateFieldHints;
  304.   public
  305.     { Public declarations }
  306.   end;
  307.  
  308.   { Some useful global functions and procedures }
  309.   procedure XceedResetDefaultProperties( var xZip : TXceedZip );
  310.   procedure XceedFillAttributeList( var lstAttributes : TCheckListBox );
  311.   function  XceedGetSelectedAttributes( var lstAttributes : TCheckListBox ) : integer;
  312.   procedure XceedSetSelectedAttributes( var lstAttributes : TCheckListBox; xAttrib : xcdFileAttributes );
  313.  
  314. var
  315.   frmMain: TfrmMain;
  316.  
  317. implementation
  318.  
  319. {$R *.DFM}
  320.  
  321. {-----------------------------------------------------------------------------}
  322. { Some useful global functions and procedures                                 }
  323. {-----------------------------------------------------------------------------}
  324.  
  325. { Reset XceedZip properties }
  326. procedure XceedResetDefaultProperties( var xZip : TXceedZip );
  327. begin
  328.   xZip.BasePath := '';
  329.   xZip.CompressionLevel := xclHigh;
  330.   xZip.EncryptionPassword := '';
  331.   xZip.RequiredFileAttributes := xfaNone;
  332.   xZip.ExcludedFileAttributes := xfaNone;
  333.   xZip.FilesToProcess := '';
  334.   xZip.FilesToExclude := '';
  335.   xZip.MinDateToProcess := EncodeDate( 1900, 01, 01 );
  336.   xZip.MaxDateToProcess := EncodeDate( 9999, 12, 31 );
  337.   xZip.MinSizeToProcess := 0;
  338.   xZip.MaxSizeToProcess := 0;   { Zero means no upper limit }
  339.   xZip.SplitSize := 0;          { Zero means no split }
  340.   xZip.PreservePaths := false;
  341.   xZip.ProcessSubfolders := false;
  342.   xZip.SkipIfExisting := false;
  343.   xZip.SkipIfNotExisting := false;
  344.   xZip.SkipIfOlderDate := false;
  345.   xZip.SkipIfOlderVersion := false;
  346.   xZip.TempFolder := '';        { Empty means default Windows temp folder }
  347.   xZip.UseTempFile := true;
  348.   xZip.UnzipToFolder := '';
  349.   xZip.ZipFilename := '';
  350.   xZip.SpanMultipleDisks := xdsRemovableDrivesOnly;
  351.   xZip.ExtraHeaders := 0;
  352.  
  353.   { General SFX stuff }
  354.   xZip.SfxBinaryModule := '';
  355.   xZip.SfxResetButtons;
  356.   xZip.SfxResetMessages;
  357.   xZip.SfxResetStrings;
  358. end;
  359.  
  360. { Fill a list with Xceed attributes. Uses the Object field as a holder for
  361.   Xceed xcdFileAttributes enumeration values }
  362. procedure XceedFillAttributeList( var lstAttributes : TCheckListBox );
  363. begin
  364.   lstAttributes.Items.Clear;
  365.   lstAttributes.Items.AddObject( 'Archive', TObject( xfaArchive ) );
  366.   lstAttributes.Items.AddObject( 'Read-only', TObject( xfaReadOnly ) );
  367.   lstAttributes.Items.AddObject( 'Hidden', TObject( xfaHidden ) );
  368.   lstAttributes.Items.AddObject( 'System', TObject( xfaSystem ) );
  369.   lstAttributes.Items.AddObject( 'Volume label', TObject( xfaVolume ) );
  370.   lstAttributes.Items.AddObject( 'Folder', TObject( xfaFolder ) );
  371.   lstAttributes.Items.AddObject( 'Compressed', TObject( xfaCompressed ) );
  372. end;
  373.  
  374. { Return Xceed attributes value for selected items. Use with XceedFillAttributeList }
  375. function XceedGetSelectedAttributes( var lstAttributes : TCheckListBox ) : integer;
  376. var
  377.   i : integer;
  378.   nAttributes : integer;
  379. begin
  380.   nAttributes := xfaNone;
  381.  
  382.   for i := 0 to lstAttributes.Items.Count-1 do
  383.   begin
  384.     if lstAttributes.Checked[i] then
  385.       nAttributes := nAttributes + integer( lstAttributes.Items.Objects[i] );
  386.   end;
  387.  
  388.   result := nAttributes;
  389. end;
  390.  
  391. { Set the attributes found in the given attribute mask }
  392. procedure XceedSetSelectedAttributes( var lstAttributes : TCheckListBox;
  393.                                       xAttrib : xcdFileAttributes );
  394. var
  395.   i : integer;
  396.   xOne : xcdFileAttributes;
  397. begin
  398.   for i := 0 to lstAttributes.Items.Count-1 do
  399.   begin
  400.     xOne  := xcdFileAttributes( lstAttributes.Items.Objects[i] );
  401.     lstAttributes.Checked[i] := ( ( xOne and xAttrib ) = xOne );
  402.   end;
  403. end;
  404.  
  405. {-----------------------------------------------------------------------------}
  406. { Form's methods                                                              }
  407. {-----------------------------------------------------------------------------}
  408.  
  409. { Update hints with linefeeds for better output }
  410. procedure TfrmMain.UpdateFieldHints;
  411. begin
  412.   { Previewing }
  413.   edtPFilesToProcess.Hint := cFilesToProcessHint;
  414.   edtPFilesToExclude.Hint := cFilesToExcludeHint;
  415.   chkPProcessSubfolders.Hint := cProcessSubfoldersHint;
  416.   lstPRequiredFileAttributes.Hint := cRequiredFileAttributesHint;
  417.   lstPExcludedFileAttributes.Hint := cExcludedFileAttributesHint;
  418.   btPreviewFiles.Hint := cPreviewFilesHint;
  419.  
  420.   { Zipping }
  421.   edtZZipFilename.Hint := cZipFilenameHint;
  422.   edtZBasePath.Hint := cBasePathHint;
  423.   edtZFilesToProcess.Hint := cFilesToProcessHint;
  424.   edtZFilesToExclude.Hint := cFilesToExcludeHint;
  425.   chkZProcessSubfolders.Hint := cProcessSubfoldersHint;
  426.   chkZPreservePaths.Hint := cPreservePathsHint;
  427.   chkZUseTempFile.Hint := cUseTempFileHint;
  428.   edtZTempFolder.Hint := cTempFolderHint;
  429.   btZip.Hint := cZipHint;
  430.  
  431.   { Listing }
  432.   edtLZipFilename.Hint := cZipFilenameHint;
  433.   dtLMinDateToProcess.Hint := cMinDateToProcessHint;
  434.   dtLMaxDateToProcess.Hint := cMaxDateToProcessHint;
  435.   edtLMinSizeToProcess.Hint := cMinSizeToProcessHint;
  436.   edtLMaxSizeToProcess.Hint := cMaxSizeToProcessHint;
  437.   btList.Hint := cListZipContentsHint;
  438.  
  439.   { Unzipping }
  440.   edtUZipFilename.Hint := cZipFilenameHint;
  441.   edtUUnzipToFolder.Hint := cUnzipToFolderHint;
  442.   edtUFilesToProcess.Hint := cFilesToProcessHint;
  443.   edtUFilesToExclude.Hint := cFilesToExcludeHint;
  444.   chkUSkipIfExisting.Hint := cSkipIfExistingHint;
  445.   chkUSkipIfNotExisting.Hint := cSkipIfNotExistingHint;
  446.   chkUSkipIfOlderDate.Hint := cSkipIfOlderDateHint;
  447.   chkUSkipIfOlderVersion.Hint := cSkipIfOlderVersionHint;
  448.   btUnzip.Hint := cUnzipHint;
  449.  
  450.   { Zipping Sfx }
  451.   edtSZipFilename.Hint := cZipFilenameSfxHint;
  452.   edtSFilesToProcess.Hint := cFilesToProcessHint;
  453.   edtSSfxBinaryModule.Hint := cSfxBinaryModuleHint;
  454.   edtSTitle.Hint := cSfxStringsHint;
  455.   edtSIntro.Hint := cSfxMessagesHint;
  456.   btZipSfx.Hint := cZipSfxHint;
  457. end;
  458.  
  459. procedure TfrmMain.FormCreate(Sender: TObject);
  460. begin
  461.   { We update hints for better look. We cannot put linefeeds in property editor! }
  462.   UpdateFieldHints;
  463.  
  464.   { We fill attribute lists }
  465.   XceedFillAttributeList( lstPRequiredFileAttributes );
  466.   XceedFillAttributeList( lstPExcludedFileAttributes );
  467.  
  468.   { We set their initial state }
  469.   XceedSetSelectedAttributes( lstPRequiredFileAttributes,
  470.                               xZip.RequiredFileAttributes );
  471.   XceedSetSelectedAttributes( lstPExcludedFileAttributes,
  472.                               xZip.ExcludedFileAttributes );
  473. end;
  474.  
  475. {-----------------------------------------------------------------------------}
  476. { Examples of how to use XceedZip                                             }
  477. {-----------------------------------------------------------------------------}
  478.  
  479. { PreviewFiles example:
  480.   This method let's you list all files (through the "OnPreviewingFile" event)
  481.   that would be processed by the Zip method with the same property values. }
  482. procedure TfrmMain.btPreviewFilesClick(Sender: TObject);
  483. var
  484.   xErr : xcdError;
  485. begin
  486.   { To be sure other tabs settings do not interfere with this example, we
  487.     start by resetting XceedZip properties to default values }
  488.   XceedResetDefaultProperties( xZip );
  489.  
  490.   { Clear the result list before starting }
  491.   edtResults.Clear;
  492.   edtResults.Lines.Add( 'PreviewFiles example:' );
  493.  
  494.   { Set properties displayed on this tab }
  495.   xZip.FilesToProcess := edtPFilesToProcess.Text;   { required }
  496.   xZip.FilesToExclude := edtPFilesToExclude.Text;
  497.   xZip.ProcessSubfolders := chkPProcessSubfolders.Checked;
  498.   xZip.RequiredFileAttributes := XceedGetSelectedAttributes( lstPRequiredFileAttributes );
  499.   xZip.ExcludedFileAttributes := XceedGetSelectedAttributes( lstPExcludedFileAttributes );
  500.  
  501.   { Launch the previewing }
  502.   xErr := xZip.PreviewFiles( false );
  503. end;
  504.  
  505. { Zip method:
  506.   The files that are matched by the filtering properties will be added to the
  507.   zip file specified by the ZipFilename property. }
  508. procedure TfrmMain.btZipClick(Sender: TObject);
  509. var
  510.   xErr : xcdError;
  511. begin
  512.   { To be sure other tabs settings do not interfere with this example, we
  513.     start by resetting XceedZip properties to default values }
  514.   XceedResetDefaultProperties( xZip );
  515.  
  516.   { Clear the result list before starting }
  517.   edtResults.Lines.Clear;
  518.   edtResults.Lines.Add( 'Zip example:' );
  519.  
  520.   { Set properties displayed on this tab }
  521.   xZip.ZipFilename := edtZZipFilename.Text;       { required }
  522.   xZip.BasePath := edtZBasePath.Text;
  523.   xZip.FilesToProcess := edtZFilesToProcess.Text; { required }
  524.   xZip.FilesToExclude := edtZFilesToExclude.Text;
  525.   xZip.ProcessSubfolders := chkZProcessSubfolders.Checked;
  526.   xZip.PreservePaths := chkZPreservePaths.Checked;
  527.   xZip.UseTempFile := chkZUseTempFile.Checked;
  528.   xZip.TempFolder := edtZTempFolder.Text;
  529.  
  530.   { Launch the zipping }
  531.   xErr := xZip.Zip;
  532. end;
  533.  
  534. { ListZipContents method:
  535.   Lists (through the OnListingFile event) the files contained in the zip file
  536.   specified by the ZipFilename property. You can set the filtering propeties
  537.   to list only particular files, or leave the FilesToProcess empty to list
  538.   everything. }
  539. procedure TfrmMain.btListClick(Sender: TObject);
  540. var
  541.   xErr : xcdError;
  542. begin
  543.   { To be sure other tabs settings do not interfere with this example, we
  544.     start by resetting XceedZip properties to default values }
  545.   XceedResetDefaultProperties( xZip );
  546.  
  547.   { Clear the result list before starting }
  548.   edtResults.Lines.Clear;
  549.   edtResults.Lines.Add( 'ListZipContents example:' );
  550.  
  551.   { Set properties displayed on this tab }
  552.   xZip.ZipFilename := edtLZipFilename.Text;           { required }
  553.   xZip.MinDateToProcess := dtLMinDateToProcess.Date;
  554.   xZip.MaxDateToProcess := dtLMaxDateToProcess.Date;
  555.   xZip.MinSizeToProcess := StrToIntDef( edtLMinSizeToProcess.Text, 0 );
  556.   xZip.MaxSizeToProcess := StrToIntDef( edtLMaxSizeToProcess.Text, 0 );
  557.  
  558.   { Launch the listing }
  559.   xErr := xZip.ListZipContents;
  560. end;
  561.  
  562. { Unzip method:
  563.   Unzips from the specified zip file (ZipFilename property) files that match
  564.   the filtering properties. }
  565. procedure TfrmMain.btUnzipClick(Sender: TObject);
  566. var
  567.   xErr : xcdError;
  568. begin
  569.   { To be sure other tabs settings do not interfere with this example, we
  570.     start by resetting XceedZip properties to default values }
  571.   XceedResetDefaultProperties( xZip );
  572.  
  573.   { Clear the result list before starting }
  574.   edtResults.Lines.Clear;
  575.   edtResults.Lines.Add( 'Unzip example:' );
  576.  
  577.   { Set properties displayed on this tab }
  578.   xZip.ZipFilename := edtUZipFilename.Text;       { required }
  579.   xZip.UnzipToFolder := edtUUnzipToFolder.Text;   { required }
  580.   xZip.FilesToProcess := edtUFilesToProcess.Text; { required }
  581.   xZip.FilesToExclude := edtUFilesToExclude.Text;
  582.   xZip.SkipIfExisting := chkUSkipIfExisting.Checked;
  583.   xZip.SkipIfNotExisting := chkUSkipIfNotExisting.Checked;
  584.   xZip.SkipIfOlderDate := chkUSkipIfOlderDate.Checked;
  585.   xZip.SkipIfOlderVersion := chkUSkipIfOlderVersion.Checked;
  586.  
  587.   { Launch the unzipping }
  588.   xErr := xZip.Unzip;
  589. end;
  590.  
  591. { Zip method:
  592.   When SfxBinaryModule contains a filename, then the resulting zip file is a
  593.   self-extracting zip file that uses this binary module as a binary header.
  594.   But appart from that (and changing the Sfx options with the Sfx properties),
  595.   creating a self-extracting zip file is just like creating a normal zip file. }
  596. procedure TfrmMain.btZipSfxClick(Sender: TObject);
  597. var
  598.   xErr : xcdError;
  599. begin
  600.   { To be sure other tabs settings do not interfere with this example, we
  601.     start by resetting XceedZip properties to default values }
  602.   XceedResetDefaultProperties( xZip );
  603.  
  604.   { Clear the result list before starting }
  605.   edtResults.Lines.Clear;
  606.   edtResults.Lines.Add( 'Zip Sfx example:' );
  607.  
  608.   { Set properties displayed on this tab }
  609.   xZip.ZipFilename := edtSZipFilename.Text;         { required }
  610.   xZip.FilesToProcess := edtSFilesToProcess.Text;   { required }
  611.   xZip.SfxBinaryModule := edtSSfxBinaryModule.Text; { required to make an EXE }
  612.   xZip.SfxStrings[ xssTitle ] := edtSTitle.Text;
  613.   xZip.SfxMessages[ xsmIntro ] := edtSIntro.Text;
  614.  
  615.   { Launch the zipping }
  616.   xErr := xZip.Zip;
  617. end;
  618.  
  619. {-----------------------------------------------------------------------------}
  620. { XceedZip events handling examples                                           }
  621. {-----------------------------------------------------------------------------}
  622.  
  623. { OnFileStatus event:
  624.   Triggered during processing of a file, at every 32k. Gives a status on each
  625.   file, one at a time, while it is being processed. Perfect for a file by file
  626.   progress bar. You can use the CurrentOperation property to recall what this
  627.   XceedZip instance is doing and display a proper status message. }
  628. procedure TfrmMain.xZipFileStatus(Sender: TObject;
  629.   const sFilename: WideString; lSize, lCompressedSize,
  630.   lBytesProcessed: Integer; nBytesPercent, nCompressionRatio: Smallint;
  631.   bFileCompleted: WordBool);
  632. begin
  633.   if lBytesProcessed = 0 then
  634.   begin
  635.     case TXceedZip( Sender ).CurrentOperation of
  636.     xcoZipping:
  637.       edtResults.Lines.Add( 'Zipping ' + sFilename );
  638.     xcoUnzipping:
  639.       edtResults.Lines.Add( 'Zipping ' + sFilename );
  640.     end;
  641.   end;
  642. end;
  643.  
  644. { OnGlobalStatus event:
  645.   Triggered during processing of files, at every 32k. Gives general status of
  646.   the complete process. Perfect for a general progress bar. }
  647. procedure TfrmMain.xZipGlobalStatus(Sender: TObject; lFilesTotal,
  648.   lFilesProcessed, lFilesSkipped: Integer; nFilesPercent: Smallint;
  649.   lBytesTotal, lBytesProcessed, lBytesSkipped: Integer;
  650.   nBytesPercent: Smallint; lBytesOutput: Integer;
  651.   nCompressionRatio: Smallint);
  652. begin
  653.   barGlobal.Position := nBytesPercent;
  654. end;
  655.  
  656. { OnInsertDisk event:
  657.   Triggered when processing a spanned zip file, or when creating a spanned zip
  658.   file and the current disk is filled. When nDiskNumber is zero, it means the
  659.   last disk of the set is required, in order to read the zip file's list of
  660.   files. }
  661. procedure TfrmMain.xZipInsertDisk(Sender: TObject; nDiskNumber: Integer;
  662.   var bDiskInserted: WordBool);
  663. var
  664.   nAnswer : Word;
  665. begin
  666.   { When nDiskNumber is 0, this means the last disk of the set is required }
  667.   if nDiskNumber = 0 then
  668.     nAnswer := MessageDlg( 'This file is part of a multidisk zip file. Please ' +
  669.                            'insert the last disk of the set.', mtInformation,
  670.                            [mbOK,mbCancel], 0 )
  671.   else
  672.     nAnswer := MessageDlg( 'Please insert disk #' + IntToStr( nDiskNumber ) + '.',
  673.                            mtInformation, [mbOK,mbCancel], 0 );
  674.  
  675.   if nAnswer = mrOK then
  676.     bDiskInserted := true;
  677. end;
  678.  
  679. { OnListingFile event:
  680.   Triggered while listing the contents of a zip file with the ListZipContents
  681.   method. }
  682. procedure TfrmMain.xZipListingFile(Sender: TObject; const sFilename,
  683.   sComment: WideString; lSize, lCompressedSize: Integer;
  684.   nCompressionRatio: Smallint; xAttributes: TOleEnum; lCRC: Integer;
  685.   dtLastModified, dtLastAccessed, dtCreated: TDateTime; xMethod: TOleEnum;
  686.   bEncrypted: WordBool; lDiskNumber: Integer; bExcluded: WordBool;
  687.   xReason: TOleEnum);
  688. begin
  689.   if bExcluded then
  690.     edtResults.Lines.Add( 'Excluding ' + sFilename + ' (reason: ' + IntToStr( xReason ) + ')' )
  691.   else
  692.     edtResults.Lines.Add( 'Including ' + sFilename );
  693. end;
  694.  
  695. { OnPreviewingFile event:
  696.   Triggered when previewing files on disk with the PreviewFiles method. }
  697. procedure TfrmMain.xZipPreviewingFile(Sender: TObject; const sFilename,
  698.   sSourceFilename: WideString; lSize: Integer; xAttributes: TOleEnum;
  699.   dtLastModified, dtLastAccessed, dtCreated: TDateTime;
  700.   bExcluded: WordBool; xReason: TOleEnum);
  701. begin
  702.   if bExcluded then
  703.     edtResults.Lines.Add( 'Excluding ' + sFilename + ' (reason: ' + IntToStr( xReason ) + ')' )
  704.   else
  705.     edtResults.Lines.Add( 'Including ' + sFilename );
  706. end;
  707.  
  708. { OnProcessCompleted event:
  709.   Triggered when any process submitted terminates. It is highly useful when
  710.   processing files with BackgroundProcessing set to true. This is how you
  711.   know the process completed! }
  712. procedure TfrmMain.xZipProcessCompleted(Sender: TObject; lFilesTotal,
  713.   lFilesProcessed, lFilesSkipped, lBytesTotal, lBytesProcessed,
  714.   lBytesSkipped, lBytesOutput: Integer; nCompressionRatio: Smallint;
  715.   xResult: TOleEnum);
  716. begin
  717.   { Display the error number and default message }
  718.   edtResults.Lines.Add( 'Process completed with error code ' + IntToStr( xResult ) );
  719.   edtResults.Lines.Add( '-=> ' + TXceedZip( Sender ).GetErrorDescription( xvtError, xResult ) );
  720.  
  721.   { Display statistics }
  722.   case TXceedZip( Sender ).CurrentOperation of
  723.   xcoZipping, xcoUnzipping, xcoRemoving:
  724.   begin
  725.     edtResults.Lines.Add( IntToStr( lFilesProcessed ) + ' file(s) processed for ' +
  726.                           IntToStr( lBytesProcessed ) + ' bytes' );
  727.     edtResults.Lines.Add( IntToStr( lFilesSkipped ) + ' file(s) skipped for ' +
  728.                           IntToStr( lBytesSkipped ) + ' bytes' );
  729.   end;
  730.   xcoListing:
  731.     edtResults.Lines.Add( IntToStr( lFilesTotal ) + ' file(s) listed' );
  732.   xcoPreviewing:
  733.     edtResults.Lines.Add( IntToStr( lFilesTotal ) + ' file(s) previewed' );
  734.   end;
  735. end;
  736.  
  737. { OnReplacingFile event:
  738.   Triggered while zipping or unzipping, when a file is about to be replaced.
  739.   The default value of the bReplaceFile parameter is true, so you do not need
  740.   to implement anything if you always want to replace files. }
  741. procedure TfrmMain.xZipReplacingFile(Sender: TObject; const sFilename,
  742.   sComment: WideString; lSize: Integer; xAttributes: TOleEnum;
  743.   dtLastModified, dtLastAccessed, dtCreated: TDateTime;
  744.   const sOrigFilename: WideString; lOrigSize: Integer;
  745.   xOrigAttributes: TOleEnum; dtOrigLastModified, dtOrigLastAccessed,
  746.   dtOrigCreated: TDateTime; var bReplaceFile: WordBool);
  747. begin
  748.   { We'll stick to the default behavior of replacing everything ! }
  749. end;
  750.  
  751. { OnSkippingFile event:
  752.   Triggered during any processing, when a file is excluded because of the
  753.   filtering properties (0 < xReason < 100), or because an error prevented this
  754.   file from being processed (xReason >= 100). }
  755. procedure TfrmMain.xZipSkippingFile(Sender: TObject; const sFilename,
  756.   sComment, sFilenameOnDisk: WideString; lSize, lCompressedSize: Integer;
  757.   xAttributes: TOleEnum; lCRC: Integer; dtLastModified, dtLastAccessed,
  758.   dtCreated: TDateTime; xMethod: TOleEnum; bEncrypted: WordBool;
  759.   xReason: TOleEnum);
  760. begin
  761.   edtResults.Lines.Add( 'Skipping ' + sFilename + ' (reason: ' + IntToStr( xReason ) + ')' );
  762. end;
  763.  
  764. { OnWarning event:
  765.   Triggered during processing when a recoverable error is encountered. }
  766. procedure TfrmMain.xZipWarning(Sender: TObject;
  767.   const sFilename: WideString; xWarning: TOleEnum);
  768. begin
  769.   edtResults.Lines.Add( 'Warnign ' + IntToStr( xWarning ) );
  770. end;
  771.  
  772. { OnZipContentsStatus event:
  773.   Triggered while reading the contents of an existing zip file. This happens
  774.   when unzipping, adding files to an existing zip file, removing files,
  775.   testing a zip file, converting a zip file, or getting the zip file's info.
  776.   This event is useful when dealing with very large zip files, and you want
  777.   to display a progress status while the zip file is read. }
  778. procedure TfrmMain.xZipZipContentsStatus(Sender: TObject; lFilesRead,
  779.   lFilesTotal: Integer; nFilesPercent: Smallint);
  780. begin
  781.   { We're not doing anything special here! }
  782. end;
  783.  
  784. end.
  785.  
  786.